﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BLL;
using Entity;
namespace BookStore.Controllers
{
    public class BooksController : Controller
    {
        //
        // GET: /Books/
        //图书类别信息
        public ActionResult BookType()
        {
            ViewBag.tt = L_BooksBLL.SeleteMessage();
            return View();
        }
        //添加图书类型
        public ActionResult AddType()
        {
            return View();
        }
        [HttpPost]
        public ActionResult AddType(BookType BT)
        {
            BookType B = new BookType();
            B.TypeName = BT.TypeName;
            B.state = BT.state;
            B.Note = BT.Note;
            L_BooksBLL.AddType(B);
            return RedirectToAction("BookType");
        }
        //修改图书类型
        public ActionResult UpdateType()
        {
            string TypeID = Request["TypeID"];
            BookType b = new BookType();
            b.TypeID = Convert.ToInt32(TypeID);
            ViewBag.tt = L_BooksBLL.UpdateTypeMessage(b);
            return View();
        }
        [HttpPost]
        //修改图书类型
        public ActionResult UpdateType(BookType BT)
        {
            BookType b = new BookType();
            b.TypeID = BT.TypeID;
            b.TypeName = BT.TypeName;
            b.state = BT.state;
            b.Note = BT.Note;
            L_BooksBLL.UpdateType(b);
            return RedirectToAction("BookType");
        }
        //图书信息管理
        public ActionResult BookMessage()
        {
            ViewBag.tt = L_BooksBLL.SeleteBookMessage();
            return View();
        }
        //图书信息管理
        [HttpPost]
        public ActionResult BookMessage(string  BookName)
        {
            BookInformatica b = new BookInformatica();
            b.BookName = BookName;
            L_BooksBLL.SeleteBookMessages(b);
            ViewBag.tt = L_BooksBLL.SeleteBookMessages(b);       
            return View();
        }

        //修改图书信息
        public ActionResult UpdataBook()
        {
            string BookId = Request["BookId"];
            BookInformatica b = new BookInformatica();
            b.BookId = Convert.ToInt32(BookId);
            ViewBag.tt = L_BooksBLL.UpdateBooks(b);
            return View();
        }
        [HttpPost]
        //修改图书信息
        public ActionResult UpdataBook(BookInformatica bb)
        {
            BookInformatica b = new BookInformatica();
            b.BookId = bb.BookId;
            b.BookPrice = bb.BookPrice;
            b.BookState = bb.BookState;
            b.BookDescribe = bb.BookDescribe;
            b.BookCount=bb.BookCount;
            L_BooksBLL.UpdateBooksMessage(b);
            return RedirectToAction("BookMessage");
        }
        //模糊查询已上架书籍
        public ActionResult selectBook()
        {
            ViewBag.tt = L_BooksBLL.SBooks();
            return View("BookMessage");
        }
        //模糊查询已下架书籍
        public ActionResult selectBooks()
        {
            ViewBag.tt = L_BooksBLL.SBook();
            return View("BookMessage");
        }
        //添加图书
        public ActionResult AddBook()
        {
            ViewBag.tt = L_BooksBLL.SeleteMessage();
            return View();
        }
        [HttpPost]
        public ActionResult AddBook(HttpPostedFileBase BookPicture, BookInformatica BF)
        {
            //图片上传
            string file = System.IO.Path.GetFileNameWithoutExtension(BookPicture.FileName);
            string ff = System.IO.Path.GetExtension(BookPicture.FileName);
            string a = Server.MapPath("~/Images/" + file + DateTime.Now.ToString("yyyyMMddHHmmss")+ff);
            BookPicture.SaveAs(a);
            BookInformatica b = new BookInformatica();
            b.BookName = BF.BookName;
            b.BookAuthor = BF.BookAuthor;
            b.BookPress = BF.BookPress;
            b.BookTime = BF.BookTime;
            //b.BookTime =new DateTime
            b.BookPrice = BF.BookPrice;
            b.TypeID = BF.TypeID;
            b.BookState = BF.BookState;
            b.BookDescribe = BF.BookDescribe;
            b.BookPicture = BF.BookPicture;
            b.BookNumber = BF.BookNumber;
            b.BookCount = BF.BookCount;
            L_BooksBLL.AddBook(b);
            return RedirectToAction("BookMessage");
        }
        //图书信息反馈
        public ActionResult FeedBack()
        {
            ViewBag.tt = L_BooksBLL.SelectFeedBook();
            return View();
        }
        public ActionResult UpdateFeedBack()
        {
            string FeedBackId = Request["UserId"];
            FeedBack f = new FeedBack();
            f.FeedBackId = Convert.ToInt32(FeedBackId);
            L_BooksBLL.UpdateFeedBack(f);
            return RedirectToAction("FeedBack");
        }
    }
}
